package com.projet.glb2r.Activite;


import java.io.File;
import java.util.Date;

import com.projet.glb2r.R;
import com.projet.glb2r.Objet.ObjetClient;
import com.projet.glb2r.R.id;
import com.projet.glb2r.R.layout;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ActiviteEmailFinal extends Activity implements OnClickListener{
	private Button boutonPdf ,boutonEmail, boutonRetour;
	private Date date = new Date();
	private String mail;
	private Context context;
	public static ObjetClient client;
	@Override
	public void onCreate(Bundle savedInstanceState)  {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fin);
		boutonPdf = (Button) findViewById (R.id.bVisualiser);
		boutonRetour = (Button) findViewById (R.id.bRetour);
		boutonEmail = (Button) findViewById (R.id.bMail);
		boutonPdf.setOnClickListener(this);
		boutonEmail.setOnClickListener(this);
		boutonRetour.setOnClickListener(this);
		mail = new String();
	}

	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch(arg0.getId()){
		case R.id.bVisualiser:
			//sendEmail(arg0);
			startActivity(new Intent("android.intent.action.ReadPdf"));
			break;
		case R.id.bMail:
			final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
			emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{client.getMail()});
			emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Facture");
			emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Bonjour Monsieur "+client.getNom()+" "+client.getPrenom()+",\n Ci joint votre facture.\n"+"Merci de votre confiance!");
			emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("mnt/sdcard/Factures/Facture.pdf")));
			emailIntent.setType("application/pdf");
			ActiviteEmailFinal.this.startActivity(Intent.createChooser(emailIntent, "Envoyer le Email..."));
			
			break;
		case R.id.bRetour:
			startActivity(new Intent("android.intent.action.ActiviteAccueil"));
			break;
		}
	}
	   @Override
	    public boolean onKeyDown(int keyCode, KeyEvent event)  {
	    	if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
	    		// do something on back.
	    		onBackPressed();
	    		return true;
	    	}

	    	return super.onKeyDown(keyCode, event);
	    }
	    
	    @Override
	    public void onBackPressed() {
	    // do something on back.
	    	Intent intention4 = new Intent("android.intent.action.ActiviteCreationFacture");
			startActivity(intention4);
			finish();
			
	    return;
	    }
}